class Example extends Phaser.Scene {
  path= [];
  constructor() {
    super();
  }

  preload() {
    this.load.image('bg', 'assets/e.png');
    this.load.spritesheet('player', 'assets/c.png', { frameWidth: 120, frameHeight: 80 });
  }

  create() {
    this.add.image(940, 940, 'bg').setScale(60/94).setOrigin(94/60, 94/60);
    this.player = this.physics.add.sprite(0, 0, 'player');

    // // 播放角色动画  
    var animation = this.player.anims.create({  
        key: 'walk',  
        frames: this.anims.generateFrameNumbers('player', { start: 0, end: 3 }),  
        frameRate: 8,  
        repeat: -1
    });  
    this.player.anims.play('walk');
  }

  update() {
    if (this.path && this.path.length) {
      const p = this.path.shift();
      this.player.x = p[0] * 6;
      this.player.y = p[1] * 6;
    }
  }
}

var config = {  
  type: Phaser.AUTO,  
  width: 600,  
  height: 600,
  backgroundColor: '#eee',
  physics: {  
      default: 'arcade',  
      arcade: {  
          gravity: { y: 0 },  
          debug: false  
      }  
  },  
  scene: Example
};

const game = new Phaser.Game(config);

function draw() {
  if (window.path) {
    game.scene.scenes[0].path = [...window.path].reverse();
  }
};
